using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebUtil
{
    public class SmartBinder
    {

        public static object Eval(object view, string expression)
        {
            try
            {
                return DataBinder.Eval(view, expression);
            }
            catch (Exception ex)
            {
                return "";
            }
        }

        public static string Eval(object view, string expression, string format)
        {
            return DataBinder.Eval(view, expression, format);
        }

        public static object ChildEval(object view, string relation, string expression)
        {
            return Eval((((DataRowView)view).Row.GetChildRows(relation)[0]), expression);
        }

        public static string ChildEval(object view, string relation, string expression, string format)
        {
            return Eval((((DataRowView)view).Row.GetChildRows(relation)[0]), expression, format);
        }

        public static object ChildChildEval(object view, string relation,string relation1, string expression)
        {
            return Eval(((DataRowView)view).Row.GetChildRows(relation)[0].GetChildRows(relation1)[0], expression);
        }

        public static object NestedEval(object view, string PropertyName, string expression) 
        {
           object obj= view.GetType().GetProperty(PropertyName).GetValue(view, null);
           return Eval(obj, expression);
        }
    }
}
